package com.zzw.service.Impl;

import com.zzw.bean.SysDictData;
import com.zzw.bean.SysDictDataExample;
import com.zzw.dao.SysDictDataMapper;
import com.zzw.service.SysDictDataService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysDictDataServiceImpl implements SysDictDataService {

    @Resource
    private SysDictDataMapper sysDictDataMapper;

    @Override
    public List<SysDictData> listByCondition(SysDictData sysDictData) {
        SysDictDataExample sysDictDataExample = new SysDictDataExample();
        SysDictDataExample.Criteria criteria = sysDictDataExample.createCriteria();

        criteria.andDictTypeEqualTo(sysDictData.getDictType());
        if (sysDictData.getDictLabel() != null) {
            criteria.andDictLabelEqualTo(sysDictData.getDictLabel());
        }
        if (sysDictData.getDictValue() != null) {
            criteria.andDictValueEqualTo(sysDictData.getDictValue());
        }
        return sysDictDataMapper.selectByExample(sysDictDataExample);
    }

    @Override
    public int save(SysDictData sysDictData) {
        sysDictData.setCreateUser("赵志伟");
        return sysDictDataMapper.insertSelective(sysDictData);
    }

    @Override
    public int update(SysDictData sysDictData) {
        return sysDictDataMapper.updateByPrimaryKeySelective(sysDictData);
    }

    @Override
    public int delete(Integer dicId) {
        return sysDictDataMapper.deleteByPrimaryKey(dicId);
    }
}
